from rest_framework import serializers
from user_operation.models import *
from goods.serializers import GoodSerializer


# 收藏详情序列化
class UserFavDetailSerializer(serializers.ModelSerializer):

    goods = GoodSerializer()

    class Meta:
        model = UserFav
        fields = ('goods', 'id')


# 收藏序列化
class UserFavSerializer(serializers.ModelSerializer):

    # 设置后，添加收藏时是给当前用户添加，而不需要选择用户对象
    user = serializers.HiddenField(default=serializers.CurrentUserDefault())

    class Meta:
        model = UserFav

        fields = ('user', 'goods', 'id')


# 留言序列化
class UserLeavingMessageSerializer(serializers.ModelSerializer):
    # 设置后，添加收藏时是给当前用户添加，而不需要选择用户对象
    user = serializers.HiddenField(
        default=serializers.CurrentUserDefault()
    )
    add_time = serializers.DateTimeField(read_only=True, format='%Y-%m-%d %H:%M')

    class Meta:
        model = UserLeavingMessage
        fields = '__all__'
        # fields = ("user", "message_type", "subject", "message", "file", "id", "add_time")


# 地址序列化
class UserAddressSerializer(serializers.ModelSerializer):
    # 设置后，添加收藏时是给当前用户添加，而不需要选择用户对象
    user = serializers.HiddenField(
        default=serializers.CurrentUserDefault()
    )

    add_time = serializers.DateTimeField(read_only=True, format='%Y-%m-%d %H:%M')

    class Meta:
        model = UserAddress
        fields = ("id", "user", "province", "city", "district", "address", "signer_name", "add_time", "signer_mobile")

